package socket;

import java.net.Socket;
import java.io.*;

/**
 * 
 * pfister@lgi2p 07/11/28
 *
 */
public class ClientInputThread extends BaseThread implements Protocol {

	public ClientInputThread(Socket connexion, BaseClient client) {
		super(connexion, client);
	}

	public void run() {
		try {
			BufferedReader socketReader = new BufferedReader(
					new InputStreamReader(socket.getInputStream()));
			while (!client.stop) {
				String readbuf = socketReader.readLine();
				if (readbuf != null)
				  if (!client.parseProtocol(readbuf))
					client.log("**"+readbuf);
				if (client.stop || readbuf == null || readbuf.contains(REMOVE.trim()) && readbuf.contains(client.name))
					break;//client.stop();	
			    try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					client.log("error " + e);
				}
			}
			client.stop();
			socket.close();
		} catch (IOException e) {
			client.log("error " + e);
		}

	}

}